package java7;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2{
	private String name;
	private int age;
	public PersonSortable2(String name,int age){
		this.name=name;
		this.age=age;
	}
	public String getname(){
		return name;
	}
	public int getage(){
		return age;
	}
	@Override
	public String toString() {
		return name+"-"+age;
	}
	
}

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      PersonSortable2 [] per=new PersonSortable2[n];
       Comparator <PersonSortable2> NameComparator=(o1,o2)->o1.getname().compareTo(o2.getname());
       Comparator <PersonSortable2> AgeComparator=(o1,o2)->o1.getage()-o2.getage();
      for(int i=0;i<n;i++){
    	  PersonSortable2 p=new PersonSortable2(sc.next(),sc.nextInt());
    	  per[i]=p;
      }
      
      Arrays.sort(per, NameComparator); 
      System.out.println("NameComparator:sort");
      for(PersonSortable2 p:per){
    	  System.out.println(p);
      }
      Arrays.sort(per, AgeComparator); 
      System.out.println("AgeComparator:sort");
      for(PersonSortable2 p:per){
    	  System.out.println(p);
      }
	}
}